package com.xms.security.api.controller;


import com.xms.core.module.ModuleCollection;
import com.xms.module.entity.Module;
import com.xms.security.entity.ResourceOwner;
import com.xms.security.service.IResourceOwnerService;
import com.xms.web.framework.controller.ApiBaseController;
import com.xms.web.framework.model.JsonResultObject;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author migo
 * @since 2021-09-04
 */
@RestController
@RequestMapping("/{org}/api/security/resourceowners")
public class ResourceOwnerController extends ApiBaseController {
    private IResourceOwnerService _resourceOwnerService;
    @Autowired
    public ResourceOwnerController(IResourceOwnerService resourceOwnerService){
        _resourceOwnerService = resourceOwnerService;
    }

    @ApiOperation("查询权限类型")
    @GetMapping("")
    public JsonResultObject get(){
        List<ResourceOwner> result = _resourceOwnerService.all();
        if(result != null){
            for (ResourceOwner entity : result){
                Module m = ModuleCollection.getModules().stream().filter(x->x.getName().equalsIgnoreCase(entity.getModulename())).findFirst().orElse(null);
                if(m != null){
                    entity.setModulelocalizedname(m.getLocalizedname());
                }
            }
        }
        return JOk(result);
    }
}
